

file="file.txt"
# 方法1: 大文件行读取
print("方法1: 大文件行读取")
with open(file,"r") as fp:
    while True:
        buf = fp.readline()
        if not buf:
            break
        print(buf.rstrip())  # 去除行尾 \n 多余空格
        # print(buf)

# 方法2: 小文件行读取
print("方法2: 小文件行读取")
with open(file,"r") as fp:
    for buf in fp.readlines():
        print(buf.rstrip())  # 去除行尾 \n 多余空格